init();
function init(){
    initEvent();
}
(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
})(jQuery);

function initEvent(){
    $('.modify-btn').click(function(){
        var newPwd = $('.new-pwd').val();
        var confirm = $('.confirm').val();
        var token = $.getUrlParam('token');
        if (newPwd!=confirm){
            $('.err-info').html('确认密码与设置密码不一致');
        }else{
            var data = {
                token:token,
                password:md5(newPwd),
                repassword:md5(confirm)
            }
            $.ajax({
                url:'forget-password.json',
                type:'PATCH',
                data:JSON.stringify(data),
                dataType:'json',
                contentType: 'application/json;charset=UTF-8',
                success:function(data){
                    $('.main').css('display','none');
                    $('.success').css('display','block');
                },
                error:function(err){
                    $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
                }
            })
        }
    })
}